package me.zhengjie.minbearwcs.listener.agv.task;

import lombok.RequiredArgsConstructor;
import me.zhengjie.minbearwcs.dao.agv.inf.AgvMissionDao;
import me.zhengjie.minbearwcs.dao.agv.inf.AgvMissionDetailDao;
import me.zhengjie.minbearwcs.entity.DTO.agv.event.TUSKFeedBackEvent;
import me.zhengjie.minbearwcs.entity.PO.agv.AgvMissionDetail;
import me.zhengjie.observer.event.IWcsEvent;
import me.zhengjie.observer.listener.IWcsEventListener;
import me.zhengjie.observer.type.WcsEventType;
import me.zhengjie.observer.type.agv.AgvTaskEventType;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
@RequiredArgsConstructor
public class AgvTaskStartListener implements IWcsEventListener {

    private final AgvMissionDao agvMissionDao;
    private final AgvMissionDetailDao agvMissionDetailDao;

    @Override
    public void onEvent(IWcsEvent wcsEvent) {
        TUSKFeedBackEvent feedBackEvent = (TUSKFeedBackEvent) wcsEvent;
        AgvMissionDetail agvMissionDetail = feedBackEvent.getAgvMissionDetail();

        agvMissionDetailDao.updateMarkTimeAndIsCompleteById(
                agvMissionDetail.getId(),
                LocalDateTime.now(),
                1
        );
    }

    @Override
    public WcsEventType getEventType() {
        return AgvTaskEventType.START;
    }
}
